import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @作者 ：zwx5321996
 * @时间： 2023.08.02
 * jdbc驱动连接数据库，设置参数accept_empty_str，测试空字符串
 **/

public class guc_accept_empty_str_case0051 {
    public static void main(String[] args) throws Exception {
        if (args.length < 4) {
            System.out.print("need para: host:ip,dbname,user,password");
        } else {
            Connection conn = DriverManager.getConnection(
					"jdbc:postgresql://" + args[0] + "/" + args[1] + "?LoggerLevel=off", args[2], args[3]);
            Statement stmt = null;
            stmt = conn.createStatement();
            int rc = stmt.executeUpdate(
                    "drop table if exists t_guc_0051; create table t_guc_0051(field_name char(10),id int);");
            System.out.println("createresult = " + rc);
            int insert = stmt.executeUpdate("insert into t_guc_0051 values ('',10);");
            System.out.println("insertresult = " + insert);

            ResultSet resultSet = stmt.executeQuery("select * from  t_guc_0051 where field_name='';");
            while (resultSet.next()) {
                System.out.println("col1 = " + resultSet.getString(1));
				System.out.println("col2 = " + resultSet.getString(2));
            }
        resultSet.close();
        stmt.close();
        conn.close();
        }
    }
}
